package s02;

import java.text.ParseException;
import java.util.Calendar;

/**
 * @ClassName CalendarDemo04
 * @Description add方法可以对指定日历字段的值进行加减操作，如果第二个参数为正数则加上偏移量，如果为负数则减去偏移量
 * @Author Li
 * @Date 2022/8/3 11:50
 * @ModifyDate 2022/8/3 11:50
 * @Version 1.0
 */
public class CalendarDemo04 {
    public static void main(String[] args) throws ParseException {
        // 创建Calendar对象
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        System.out.println(year + "年" + month + "月" + day + "日");
        // 使用add方法
        calendar.add(Calendar.MONTH, 1);
        calendar.add(Calendar.DAY_OF_MONTH, -14);
        int year1 = calendar.get(Calendar.YEAR);
        int month1 = calendar.get(Calendar.MONTH) + 1;
        int day1 = calendar.get(Calendar.DAY_OF_MONTH);
        System.out.println(year1 + "年" + month1 + "月" + day1 + "日");
    }
}
